﻿// ***********************************************************************
// Assembly         : Suining.Simulation
// Author           : yubaolee
// Created          : 09-18-2014
//
// Last Modified By : yubaolee
// Last Modified On : 10-11-2014
// ***********************************************************************
// <copyright file="Prompt.cs" company="e-mail:yubaolee@163.com/qq:258210592">
//     Copyright (c) e-mail:yubaolee@163.com/qq:258210592. All rights reserved.
// </copyright>
// <summary>弹出一个带有文本框的对话框</summary>
// ***********************************************************************

using System.Drawing;
using System.Windows.Forms;

namespace Suining.Simulation
{
    public static class Prompt
    {
        public static string ReturnString { get; private set; }
        public static DialogResult DialogResult { get; private set; }
        public static void ShowDialog(string caption)
        {
            var prompt = new Form
            {
                Width = 198,
                Height = 120,
                Text = caption,
                MaximizeBox = false,
                MinimizeBox = false,
                FormBorderStyle = FormBorderStyle.FixedSingle,
                StartPosition = FormStartPosition.CenterParent,
            };
            var txtMsg = new TextBox
            {
                Location = new Point(12, 12),
                PasswordChar = '*',
                Size = new Size(165, 21),
                TabIndex = 1
            };

            var btnOk = new Button
            {
                Location = new Point(12, 49),
                Size = new Size(80, 36),
                TabIndex = 2,
                Text = @"确定",
            };
            var btnCancel = new Button
            {
                Location = new Point(97, 49),
                Size = new Size(80, 36),
                TabIndex = 3,
                Text = @"取消",
            };


            btnOk.Click += (sender, e) =>
            {
                DialogResult = DialogResult.OK;
                prompt.Close();
            };
            btnCancel.Click += (sender, e) =>
            {
                DialogResult = DialogResult.Cancel;
                ReturnString = string.Empty;
                prompt.Close();
            };

            prompt.Controls.Add(txtMsg);
            prompt.Controls.Add(btnOk);
            prompt.Controls.Add(btnCancel);
            prompt.AcceptButton = btnOk;
            prompt.ShowDialog();
            ReturnString = txtMsg.Text;
        }
    }
}
